<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateShippingTemplateRelationsTable extends Migrator
{
    public function change()
    {
        $table = $this->table('shipping_template_relations');
        $table->addColumn('template_id', 'integer', ['comment' => '运费模板ID'])
            ->addColumn('biz_type', 'string', ['limit' => 50, 'comment' => '业务类型: goods(商品), category(商品分类), shop(店铺)等'])
            ->addColumn('biz_id', 'integer', ['comment' => '业务实体ID'])
            ->addTimestamps('create_time', 'update_time')
            ->addIndex(['template_id'])
            ->addIndex(['biz_type'])
            ->addIndex(['biz_id'])
            ->addIndex(['template_id', 'biz_type', 'biz_id'], ['unique' => true])
            ->create();
    }
}